<% add_decidim_page_title(t("authorizations", scope: "layouts.decidim.user_profile")) %>
<% content_for(:subtitle) { t("authorizations", scope: "layouts.decidim.user_profile") } %>
<% url_params = (redirect_url.present? ? { redirect_url: } : {}) %>

<%= append_javascript_pack_tag "decidim_verifications" %>
<%= append_stylesheet_pack_tag "decidim_verifications" %>

<%= render layout: "layouts/decidim/shared/layout_user_profile" do %>
  <section class="authorizations-list">
    <%
        subsections = []

        subsections << {
          title: t("authorizations.index.granted_verification", scope: "decidim.verifications"),
          items: granted_authorizations.map { |authorization| granted_authorization_display_data(authorization, redirect_url) }
        } if granted_authorizations.any?

        subsections << {
          title: t("authorizations.index.pending_verification", scope: "decidim.verifications"),
          items: pending_authorizations.map { |authorization| pending_authorization_display_data(authorization, redirect_url) }
        } if pending_authorizations.any?

        subsections << {
          title: t("authorizations.index.unauthorized_methods", scope: "decidim.verifications"),
          items: unauthorized_methods.map { |method| unauthorized_method_display_data(method, redirect_url) }
        } if unauthorized_methods.any?
    %>

    <% subsections.each do |subsection| %>
      <div class="verification__container-title"><%= subsection[:title] %></div>
      <div class="verification__container">
        <% subsection[:items].each do |locals| %>
          <%= render partial: "item", locals: %>
        <% end %>
      </div>
    <% end %>
  </section>
<% end %>
